<template>
	<el-container>
		<el-aside width="200px" v-loading="showGrouploading">
			<el-container>
				<el-header>
					<el-input placeholder="输入关键字进行过滤" v-model="groupFilterText" clearable></el-input>
				</el-header>
				<el-main class="nopadding">
					<el-tree ref="group" class="menu" node-key="id" :data="group" :props="groupsProps" :current-node-key="''" :highlight-current="true" :expand-on-click-node="false" :filter-node-method="groupFilterNode" @node-click="groupClick"></el-tree>
				</el-main>
			</el-container>
		</el-aside>
		<el-container>
			<el-header style="height: auto;">
				<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
			</el-header>
			<el-header>
				<div class="left-panel">
				</div>
				<div class="right-panel">
					<div class="right-panel-search">
						<el-input v-model="search.keyword" placeholder="标题 / 摘要" clearable></el-input>
						<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
					</div>
				</div>
			</el-header>
			<el-main class="nopadding">
				<scTable ref="table" :apiObj="apiObj" stripe remoteSort remoteFilter>
					<el-table-column label="#" type="index" width="50"></el-table-column>
					<el-table-column label="任务标题" prop="title" width="300" :show-overflow-tooltip="true"></el-table-column>
					<el-table-column label="事件类型" prop="typeName" width="100" :show-overflow-tooltip="true"></el-table-column>
					<el-table-column label="主办人" prop="holderUserName" width="100"></el-table-column>
					<el-table-column label="进度" prop="progress" width="100">
						<template #default="scope">
							{{scope.row.progress*100}}%
						</template>
					</el-table-column>
					<el-table-column label="完成时间" prop="finishTime" width="100"></el-table-column>
					<el-table-column label="相关附件" prop="attachId" width="200">
						<template #default="scope">
							<attach-menu :attachIds="scope.row.attachId" :roleFlag="1" :preview="true"></attach-menu>
						</template>
					</el-table-column>
					<el-table-column label="操作" fixed="right" align="right" width="120">
						<template #default="scope">
							<el-button-group>
								<el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)">查看</el-button>
								<el-button text type="primary" size="small" @click="show_process(scope.row, scope.$index)">过程</el-button>
							</el-button-group>
						</template>
					</el-table-column>
				</scTable>
			</el-main>
		</el-container>
	</el-container>
	<recordDetails v-if="dialog.detailsSave" ref="detailsDialog" @closed="dialog.detailsSave=false"></recordDetails>
	<processDetails v-if="dialog.processSave" ref="processDialog" @closed="dialog.processSave=false"></processDetails>
</template>

<script>
import scSelectFilter from '@/components/scSelectFilter'
import AttachMenu from '@/views/module/attachMenu'
import recordDetails from '@/views/supervision/task/mytask/details'
import processDetails from './processDetails'
export default {
	name: 'Supervision Process Manage',
	components: {
		AttachMenu,
		scSelectFilter,
		recordDetails,
		processDetails
	},
	data() {
		return {
			dialog: {
				detailsSave:false,
			},
			filterData: [
				{
					title: "日期范围",
					key: "date",
					multiple: false,
					options: [
						{
							label: "全部",
							value: ""
						},
						{
							label: "今日",
							value: "1"
						},
						{
							label: "昨日",
							value: "2"
						},
						{
							label: "一周内",
							value: "3"
						},
						{
							label: "一月内",
							value: "4"
						},
						{
							label: "一月前",
							value: "5"
						}
					]
				}
			],
			showGrouploading: false,
			groupFilterText: '',
			group: [],
			groupsProps: {
				label:"name",
				value: "id"
			},
			apiObj: this.$API.supervision.supervisionProcess.getControlProcessList,
			search: {
				date:'',
				supervisionId:'',
				keyword: null
			}
		}
	},
	watch: {
		groupFilterText(val) {
			this.$refs.group.filter(val);
		}
	},
	mounted() {
		this.getSupervisionTree()
	},
	methods: {
		filterChange(data){
			this.search.date = data.date;
			this.$refs.table.upData(this.search)
		},
		//加载树数据
		async getSupervisionTree(){
			this.showGrouploading = true;
			var res = await this.$API.supervision.supervision.getSupervisionTree.get();
			this.showGrouploading = false;
			this.group = res.data;
		},
		//查看
		table_show(row){
			this.dialog.detailsSave = true
			this.$nextTick(() => {
				this.$refs.detailsDialog.open().setData(row)
			})
		},
		show_process(row){
			this.dialog.processSave = true
			this.$nextTick(() => {
				this.$refs.processDialog.open().setData(row)
			})
		},
		//树过滤
		groupFilterNode(value, data){
			if (!value) return true;
			return data.name.indexOf(value) !== -1;
		},
		//树点击事件
		groupClick(data){
			console.log(data);
			if(data.isParent=="false")
			{
				this.search.supervisionId = data.id;
				this.$refs.table.reload(this.search)
			}
		},
		//搜索
		upsearch(){
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSuccess(data, mode){
			this.$refs.table.refresh()
		}
	}
}
</script>

<style>
</style>
